package com.diqizu.servlet.admin;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.diqizu.servlet.BaseServlet;
import com.diqizu.utli.Result;
import com.jspsmart.upload.SmartUpload;
import com.jspsmart.upload.SmartUploadException;

/**
 * Servlet implementation class imgServletadmin
 */
@WebServlet("/admin/ImgServletAdmin")
public class ImgServletAdmin extends BaseServlet {
	
	public void upload(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		PrintWriter out = resp.getWriter();
		SmartUpload smart=new SmartUpload();
		smart.setCharset("utf-8");
		smart.initialize(getServletConfig(), req, resp);
		try {
			smart.upload();
			smart.save("/images");
			String filename = smart.getFiles().getFile(0).getFileName();
			out.print(Result.toClient(0, "新图片上传成功", filename));
			} catch (SmartUploadException e) {
			out.print(Result.toClient(1, "上传失败","图片"));
			e.printStackTrace();
			}
			out.flush();
			out.close();
			}
	
}
